package com.tannm.doan.taskmanager;

import java.util.*;
import java.text.*;

import com.tannm.doan.taskmanager.agenda.*;
import com.tannm.doan.taskmanager.database.*;
import com.tannm.doan.taskmanager.dataview.*;
import com.tannm.doan.taskmanager.reminder.AlarmService;
import com.tannm.doan.taskmanager.views.*;
import com.tannm.doan.widgets.*;

import com.tannm.doan.taskmanager.R;
import android.view.MenuItem;
import android.view.View;
import android.view.Menu;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.*;
import android.widget.LinearLayout.*;
import android.content.Intent;
import android.os.*;
import android.content.*;

//Main activity
public class TaskManager extends CommonActivity {
	// fields

	protected TaskManager base = null;
	private Calendar dateToday = Calendar.getInstance();
	private SimpleDateFormat dateFormatFull = new SimpleDateFormat(
			"EE, dd-MM-yyyy");
	private SimpleDateFormat dateFormatMonth = new SimpleDateFormat("MMMM yyyy");

	// fields
	private int iCurrentAgendaViewType = AgendaView.viewMode.TODAY;

	// menu items
	private final int miNewAppt = Menu.FIRST;
	private final int miNewTask = Menu.FIRST + 1;
	private final int miNewNote = Menu.FIRST + 2;
	private final int miShowAllTasks = Menu.FIRST + 3;
	private final int miOptions = Menu.FIRST + 4;
	private final int miAbout = Menu.FIRST + 5;

	// views
	private ScrollView scrollViewAgenda = null;
	protected RelativeLayout rlayAgendaTop = null;

	@SuppressWarnings("all")
	protected RelativeLayout rlayAgenda = null;

	@SuppressWarnings("all")
	protected RelativeLayout rlayAgendaView = null;
	protected LinearLayout llayAgendaData = null;

	// views
	private AgendaView CurrentAgendaView = null;
	private AgendaViewToday AgendaViewToday = null;
	private AgendaViewDay AgendaViewDay = null;
	private AgendaViewWeek AgendaViewWeek = null;
	private AgendaViewMonth AgendaViewMonth = null;

	// fields
	protected DataViewAppointment dataViewAppt = null;
	protected DataViewTask dataViewTask = null;
	protected DataViewNote dataViewNote = null;

	// fields
	private Handler handlerUpdateDate = new Handler();
	private Handler handlerUpdateView = new Handler();
	private final static int iHandlerUpdateTime = 1000 * 5;
	private int iUpdateDate_minute = 0;

	// views
	private TextView labSelectViewItem = null;
	private ViewImgButton btnSelectViewItemPrev = null;
	private Button btnSelectViewItemToday = null;
	private ViewImgButton btnSelectViewItemNext = null;

	// bottom buttons
	private Button btnSetViewToday = null;
	private Button btnSetViewDay = null;
	private Button btnSetViewWeek = null;
	private Button btnSetViewMonth = null;

	// methods
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		base = this;
		setContentView(R.layout.agenda);

		initViews();
		initStateOnce();
		startReminderService();
	}

	@Override
	public void onStart() {
		super.onStart();

	}

	@Override
	public void onResume() {
		super.onResume();

	}

	@Override
	public void onPause() {
		super.onPause();

	}

	@Override
	public void onStop() {
		super.onStop();

	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		handlerUpdateDate.removeCallbacks(handlerUpdateDateTask);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);

		// build menu
		MenuItem mi = menu.add(0, miNewAppt, 0, R.string.actionNewAppointment);
		mi.setShortcut('1', 'a');
		mi.setIcon(R.drawable.menuiconappt);

		mi = menu.add(0, miNewTask, 1, R.string.actionNewTask);
		mi.setShortcut('2', 't');
		mi.setIcon(R.drawable.menuicontask);

		mi = menu.add(0, miNewNote, 2, R.string.actionNewNote);
		mi.setShortcut('3', 'n');
		mi.setIcon(R.drawable.menuiconnote);

		mi = menu.add(2, miShowAllTasks, 3, R.string.actionShowAllTasks);
		mi.setCheckable(true);
		mi.setChecked(prefs.bShowAllTasks);
		menuItemUpdateIcons(mi);

		mi = menu.add(4, miOptions, 4, R.string.actionOptions);
		mi.setShortcut('5', 'o');
		mi.setIcon(R.drawable.menuiconprefs);

		mi = menu.add(4, miAbout, 5, R.string.actionAbout);
		mi.setIcon(R.drawable.menuiconabout);

		return true;
	}

	public void menuItemUpdateIcons(MenuItem item) {
		if (item.getItemId() == miShowAllTasks)
			if (item.isChecked()) {
				item.setIcon(R.drawable.menuiconshowtasksdue);
			} else {
				item.setIcon(R.drawable.menuiconshowtasks);
			}
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case miNewAppt:
			openActAppointment(-1, -1, -1);
			break;
		case miNewTask:
			openActTask(-1);
			break;
		case miNewNote:
			openActNote(-1);
			break;
		case miShowAllTasks: {
			item.setChecked(!item.isChecked());
			prefs.bShowAllTasks = item.isChecked();
			prefs.save();
			refreshData();
			menuItemUpdateIcons(item);
			break;
		}
		case miOptions:
			openActOptions();
			break;
		case miAbout:
			openActViewAbout();
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	// initialize views
	private void initViews() {
		// localize DateWidget
		DateWidget.setStrings(utils.getResStr(R.string.strDateWidgetSelect),
				utils.getResStr(R.string.strDateWidgetSelected), utils
						.getResStr(R.string.strDateWidgetNone));

		// localize TimeWidget
		TimeWidget.setStrings(utils.getResStr(R.string.strTimeWidgetSelect),
				utils.getResStr(R.string.strTimeWidgetNone), utils
						.getResStr(R.string.strTimeWidgetSet));

		rlayAgendaTop = (RelativeLayout) findViewById(R.id.rlayAgendaTop);
		rlayAgenda = (RelativeLayout) findViewById(R.id.rlayAgenda);
		rlayAgendaView = (RelativeLayout) findViewById(R.id.rlayAgendaView);

		llayAgendaData = (LinearLayout) findViewById(R.id.llayAgendaData);

		btnSelectViewItemPrev = (ViewImgButton) findViewById(R.id.btnSelectViewItemPrev);
		btnSelectViewItemPrev.SetButtonIcon(R.drawable.btnprev, -1);
		btnSelectViewItemPrev.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				CurrentAgendaView.setPrevViewItem();
				refreshAgendaAfterViewItemChange();
			}
		});

		btnSelectViewItemToday = (Button) findViewById(R.id.btnSelectViewItemToday);
		btnSelectViewItemToday.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				CurrentAgendaView.setTodayViewItem();
				refreshAgendaAfterViewItemChange();
			}
		});

		btnSelectViewItemNext = (ViewImgButton) findViewById(R.id.btnSelectViewItemNext);
		btnSelectViewItemNext.SetButtonIcon(R.drawable.btnnext, 0);
		btnSelectViewItemNext.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				CurrentAgendaView.setNextViewItem();
				refreshAgendaAfterViewItemChange();
			}
		});
		labSelectViewItem = (TextView) findViewById(R.id.labSelectViewItem);

		// initialize change view bottom buttons
		btnSetViewToday = (Button) findViewById(R.id.btnSetViewToday);
		btnSetViewToday.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// ToggleBottomButtonsState(btnSetViewToday);
				setAgendaView(AgendaView.viewMode.TODAY, latestDateToday());
			}
		});

		btnSetViewDay = (Button) findViewById(R.id.btnSetViewDay);
		btnSetViewDay.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// ToggleBottomButtonsState(btnSetViewDay);
				setAgendaView(AgendaView.viewMode.DAY, latestDateToday());
			}
		});

		btnSetViewWeek = (Button) findViewById(R.id.btnSetViewWeek);
		btnSetViewWeek.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// ToggleBottomButtonsState(btnSetViewWeek);
				setAgendaView(AgendaView.viewMode.WEEK, latestDateToday());
			}
		});

		btnSetViewMonth = (Button) findViewById(R.id.btnSetViewMonth);
		btnSetViewMonth.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// ToggleBottomButtonsState(btnSetViewMonth);
				setAgendaView(AgendaView.viewMode.MONTH, latestDateToday());
			}
		});

		// initialize data views
		dataViewAppt = new DataViewAppointment(userdb, prefs);
		dataViewTask = new DataViewTask(userdb, prefs);
		dataViewNote = new DataViewNote(userdb, prefs);

		initAgendaViewToday();
	}

	public void toggleBottomButtonsState(CompoundButton btnClicked) {
		btnClicked.setEnabled(false);
		btnClicked.requestFocus();

		if (btnClicked != btnSetViewToday)
			btnSetViewToday.setEnabled(true);
		if (btnClicked != btnSetViewDay)
			btnSetViewDay.setEnabled(true);
		if (btnClicked != btnSetViewWeek)
			btnSetViewWeek.setEnabled(true);
		if (btnClicked != btnSetViewMonth)
			btnSetViewMonth.setEnabled(true);
	}

	public void updateBottomButtonsStateByCurrentView() {
		/*
		 * if (iCurrentAgendaViewType == AgendaView.viewMode.TODAY)
		 * ToggleBottomButtonsState(btnSetViewToday); if (iCurrentAgendaViewType
		 * == AgendaView.viewMode.DAY) ToggleBottomButtonsState(btnSetViewDay);
		 * if (iCurrentAgendaViewType == AgendaView.viewMode.WEEK)
		 * ToggleBottomButtonsState(btnSetViewWeek); if (iCurrentAgendaViewType
		 * == AgendaView.viewMode.MONTH)
		 * ToggleBottomButtonsState(btnSetViewMonth);
		 */
	}

	public void initAgendaViewToday() {
		// initialize today agenda view
		AgendaViewToday = new AgendaViewToday(this);
		AgendaViewToday.rebuild();

		// set click event for all agenda views
		AgendaView.setItemClick(new AgendaView.OnViewItemClick() {
			public void OnClick(View v, Bundle extras) {
				long lRowId = extras.getLong(CommonActivity.bundleRowId);
				if (extras.getString("type").equals(
						ViewTodayItemHeader.ViewType.Appointments.toString())) {
					if (extras.containsKey(CommonActivity.bundleHourOfDay)) {
						openActAppointment(lRowId, extras
								.getInt(CommonActivity.bundleHourOfDay), extras
								.getInt(CommonActivity.bundleMinutes));
					} else {
						openActAppointment(lRowId, -1, -1);
					}
				}
				if (extras.getString("type").equals(
						ViewTodayItemHeader.ViewType.Tasks.toString()))
					openActTask(lRowId);
				if (extras.getString("type").equals(
						ViewTodayItemHeader.ViewType.Notes.toString()))
					openActNote(lRowId);
			}
		});

		// initialize all other agenda views
		AgendaViewDay = new AgendaViewDay(TaskManager.this);
		AgendaViewDay.rebuild();

		AgendaViewWeek = new AgendaViewWeek(TaskManager.this);
		AgendaViewWeek.rebuild();

		AgendaViewMonth = new AgendaViewMonth(TaskManager.this);
		AgendaViewMonth.rebuild();

		// initialize scrollable content
		scrollViewAgenda = new ScrollView(this);
		LayoutParams layParams = new LayoutParams(
				android.view.ViewGroup.LayoutParams.FILL_PARENT,
				android.view.ViewGroup.LayoutParams.FILL_PARENT);
		scrollViewAgenda.setLayoutParams(layParams);
	}

	private void initStateOnce() {
		reloadAllDataTables();
		// ToggleBottomButtonsState(btnSetViewToday);
		setAgendaView(AgendaView.viewMode.TODAY, latestDateToday());

		// refresh view (relayout bug)
		forceUpdateLayout();

		// schedule handler update date task
		handlerUpdateDate.removeCallbacks(handlerUpdateDateTask);
		handlerUpdateDate
				.postDelayed(handlerUpdateDateTask, iHandlerUpdateTime);

		// focus default button
		btnSetViewToday.requestFocus();
	}

	private void forceUpdateLayout() {
		handlerUpdateView.removeCallbacks(handlerUpdateViewTask);
		handlerUpdateView.postDelayed(handlerUpdateViewTask, 100);
	}

	private Runnable handlerUpdateViewTask = new Runnable() {
		public void run() {
			rlayAgenda.postInvalidate();
			rlayAgenda.requestLayout();
			rlayAgendaView.postInvalidate();
			rlayAgendaView.requestLayout();
		}
	};

	private Runnable handlerUpdateDateTask = new Runnable() {
		public void run() {
			try {
				updateTodayDate();

				// refresh data, if system timer minute changed
				if (iUpdateDate_minute != dateToday.get(Calendar.MINUTE)) {
					iUpdateDate_minute = dateToday.get(Calendar.MINUTE);

					// autorefresh only today view
					if (iCurrentAgendaViewType == AgendaView.viewMode.TODAY) {
						if (CurrentAgendaView != null)
							CurrentAgendaView
									.setViewStartDate(latestDateToday());
						refreshData();
					}
				}
			} finally {
				handlerUpdateDate.postDelayed(this, iHandlerUpdateTime);
			}
		}
	};

	// refresh start view date
	public synchronized void updateTodayDate() {
		dateToday.setTimeInMillis(System.currentTimeMillis());
		dateToday.setFirstDayOfWeek(prefs.iFirstDayOfWeek);
	}

	public synchronized void refreshData() {
		// set title
		setActivityTitle(utils.getLongDate(dateToday));

		// update view info view
		updateSelectViewText(iCurrentAgendaViewType);

		// update button text date
		updateCurrentViewItemDate();

		// reload data
		if (userdb.databaseReady()) {
			// filter data
			dataViewAppt.filterData(CurrentAgendaView.getViewStartDate(),
					CurrentAgendaView.getViewType());
			if (iCurrentAgendaViewType == AgendaView.viewMode.TODAY) {
				dataViewTask.filterData(CurrentAgendaView.getViewStartDate(),
						CurrentAgendaView.getViewType());
				dataViewNote.filterData(CurrentAgendaView.getViewStartDate(),
						CurrentAgendaView.getViewType());
			}
			// rebuild views
			CurrentAgendaView.rebuildViewAppointments(dataViewAppt);
			if (iCurrentAgendaViewType == AgendaView.viewMode.TODAY) {
				CurrentAgendaView.rebuildViewTasks(dataViewTask);
				CurrentAgendaView.rebuildViewNotes(dataViewNote);
			}
		}

		// set scroll view top position
		scrollViewAgenda.scrollTo(0, 0);
	}

	public void refreshAgendaAfterViewItemChange() {
		btnSelectViewItemToday.setText("...");

		// filter data
		dataViewAppt.filterData(CurrentAgendaView.getViewStartDate(),
				CurrentAgendaView.getViewType());

		// rebuild view
		CurrentAgendaView.rebuildViewAppointments(dataViewAppt);

		updateCurrentViewItemDate();
	}

	public void updateCurrentViewItemDate() {
		String s = "";
		if (iCurrentAgendaViewType == AgendaView.viewMode.DAY)
			s = dateFormatFull.format(
					CurrentAgendaView.getViewStartDate().getTime()).toString();
		if (iCurrentAgendaViewType == AgendaView.viewMode.WEEK)
			s = dateFormatFull.format(
					CurrentAgendaView.getViewStartDate().getTime()).toString();
		if (iCurrentAgendaViewType == AgendaView.viewMode.MONTH)
			s = dateFormatMonth.format(
					CurrentAgendaView.getCurrentSelectedMonthAsCalendar()
							.getTime()).toString();
		btnSelectViewItemToday.setText(s);
	}

	// main program date holder
	public Calendar getDateToday() {
		dateToday.setFirstDayOfWeek(prefs.iFirstDayOfWeek);
		return dateToday;
	}

	public Calendar latestDateToday() {
		updateTodayDate();
		return getDateToday();
	}

	public void reloadDataTable(String sTableNameToReload) {
		if (userdb.databaseReady()) {
			if (sTableNameToReload.equals(Database.sTableNameAppointments))
				dataViewAppt.reloadTable();
			if (sTableNameToReload.equals(Database.sTableNameTasks))
				dataViewTask.reloadTable();
			if (sTableNameToReload.equals(Database.sTableNameNotes))
				dataViewNote.reloadTable();
		}
	}

	public void reloadAllDataTables() {
		if (userdb.databaseReady()) {
			dataViewAppt.reloadTable();
			dataViewTask.reloadTable();
			dataViewNote.reloadTable();
		}
	}

	private void updateSelectViewText(int viewType) {
		String s = "";
		if (iCurrentAgendaViewType == AgendaView.viewMode.DAY)
			s = utils.getResStr(R.string.labSelectViewDay);
		if (iCurrentAgendaViewType == AgendaView.viewMode.WEEK)
			s = utils.getResStr(R.string.labSelectViewWeek);
		if (iCurrentAgendaViewType == AgendaView.viewMode.MONTH)
			s = utils.getResStr(R.string.labSelectViewMonth);
		labSelectViewItem.setText(s);
	}

	public synchronized void setAgendaView(int viewType, Calendar calViewDate) {
		if (userdb.databaseReady()) {
			// init view
			iCurrentAgendaViewType = viewType;

			showTopControls(iCurrentAgendaViewType != AgendaView.viewMode.TODAY);

			// change type
			if (iCurrentAgendaViewType == AgendaView.viewMode.TODAY)
				CurrentAgendaView = AgendaViewToday;
			if (iCurrentAgendaViewType == AgendaView.viewMode.DAY)
				CurrentAgendaView = AgendaViewDay;
			if (iCurrentAgendaViewType == AgendaView.viewMode.WEEK)
				CurrentAgendaView = AgendaViewWeek;
			if (iCurrentAgendaViewType == AgendaView.viewMode.MONTH)
				CurrentAgendaView = AgendaViewMonth;

			if (CurrentAgendaView != null)
				CurrentAgendaView.setViewStartDate(calViewDate);

			// reload data
			refreshData();

			// set view change buttons
			updateBottomButtonsStateByCurrentView();

			visibleLayoutContentRemove();
			visibleLayoutContentAdd();

		} else {
			utils.showMsgResStr(Database.getErrDesc(userdb
					.tablesCreationResult()), Utils.MSGTYPE_ERROR);
		}
	}

	private void visibleLayoutContentRemove() {
		llayAgendaData.removeAllViews();
		scrollViewAgenda.removeAllViews();
	}

	private void visibleLayoutContentAdd() {
		if (iCurrentAgendaViewType == AgendaView.viewMode.TODAY) {
			scrollViewAgenda.addView(CurrentAgendaView.getParentLayout());
			llayAgendaData.addView(scrollViewAgenda);
		}
		if (iCurrentAgendaViewType == AgendaView.viewMode.DAY) {
			scrollViewAgenda.addView(CurrentAgendaView.getParentLayout());
			llayAgendaData.addView(scrollViewAgenda);
		}
		if (iCurrentAgendaViewType == AgendaView.viewMode.WEEK) {
			llayAgendaData.addView(CurrentAgendaView.getParentLayout());
		}
		if (iCurrentAgendaViewType == AgendaView.viewMode.MONTH) {
			llayAgendaData.addView(CurrentAgendaView.getParentLayout());
		}
	}

	private void showTopControls(boolean bEnable) {
		// enable
		btnSelectViewItemPrev.setEnabled(bEnable);
		btnSelectViewItemToday.setEnabled(bEnable);
		btnSelectViewItemNext.setEnabled(bEnable);
		rlayAgendaTop.setEnabled(bEnable);

		// focus
		btnSelectViewItemPrev.setFocusable(bEnable);
		btnSelectViewItemToday.setFocusable(bEnable);
		btnSelectViewItemNext.setFocusable(bEnable);
		rlayAgendaTop.setFocusable(bEnable);

		// visibility
		btnSelectViewItemPrev.setVisibility((bEnable) ? View.VISIBLE
				: View.INVISIBLE);
		btnSelectViewItemToday.setVisibility((bEnable) ? View.VISIBLE
				: View.INVISIBLE);
		btnSelectViewItemNext.setVisibility((bEnable) ? View.VISIBLE
				: View.INVISIBLE);

		// resize layout
		MarginLayoutParams mlp = (MarginLayoutParams) rlayAgendaTop
				.getLayoutParams();
		mlp.setMargins(0, 0, 0, 0);
		rlayAgendaTop.getLayoutParams().height = 0;
		if (bEnable) {
			rlayAgendaTop.getLayoutParams().height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
			mlp.setMargins(0, 0, 0, 6);
		}

		// refresh view (relayout bug)
		forceUpdateLayout();
	}

	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		// todo...
	}

	public void openActAppointment(long lRowId, int iHourOfDay, int iMinutes) {
		bundleOtherDataStartup.clear();
		if (lRowId == -1) {
			bundleOtherDataStartup.putInt(CommonActivity.bundleAgendaView,
					CurrentAgendaView.getViewIndex());
			bundleOtherDataStartup.putLong(
					CommonActivity.bundleAgendaViewStartDate, CurrentAgendaView
							.getViewStartDate().getTimeInMillis());

			if (iHourOfDay != -1)
				bundleOtherDataStartup.putInt(CommonActivity.bundleHourOfDay,
						iHourOfDay);
			if (iMinutes != -1)
				bundleOtherDataStartup.putInt(CommonActivity.bundleMinutes,
						iMinutes);

			openActivity(0, "android.intent.action.TaskManager.ACTION_MODE_NEW_APPOINTMENT");
		} else {
			openActivity(0,"android.intent.action.TaskManager.ACTION_MODE_EDIT_APPOINTMENT", lRowId);
		}
	}

	public void openActTask(long lRowId) {
		bundleOtherDataStartup.clear();
		if (lRowId == -1)
			openActivity(0, "android.intent.action.TaskManager.ACTION_MODE_NEW_TASK");
		else
			openActivity(0, "android.intent.action.TaskManager.ACTION_MODE_EDIT_TASK", lRowId);
	}

	public void openActNote(long lRowId) {
		bundleOtherDataStartup.clear();
		if (lRowId == -1)
			openActivity(0, "android.intent.action.TaskManager.ACTION_MODE_NEW_NOTE");
		else
			openActivity(0,
					"android.intent.action.TaskManager.ACTION_MODE_EDIT_NOTE", lRowId);
	}

	public void openActOptions() {
		bundleOtherDataStartup.clear();
		openActivity(0, "android.intent.action.TaskManager.ACTION_MODE_EDIT_OPTIONS");
	}

	public void openActViewAbout() {
		bundleOtherDataStartup.clear();
		openActivity(0, "android.intent.action.TaskManager.ACTION_MODE_VIEW_ABOUT");
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		Bundle extras = CommonActivity.getIntentExtras(data);
		if (extras != null) {
			if (resultCode == RESULT_OK) {
				// state refresh, because of table updated
				if (extras.containsKey(CommonActivity.bundleTableUpdated)) {
					String sTableNameToReload = extras
							.getString(CommonActivity.bundleTableUpdated);
					reloadDataTable(sTableNameToReload);
					refreshData();
					updateReminderService(this, prefs,
							CommonActivity.bundleTableUpdated);
				}
				// state refresh, because of options updated
				if (extras.containsKey(CommonActivity.bundleOptionsUpdated)) {
					prefs.load();
					if (CurrentAgendaView.timeFormatChanged())
						CurrentAgendaView.updateTimeFormat();
					CurrentAgendaView.setTodayViewItem();
					refreshData();
					updateReminderService(this, prefs,
							CommonActivity.bundleOptionsUpdated);
				}
			}
		}
	}

	public int getViewSpaceWidth() {
		// return rlayAgendaView.getWidth();
		return 320 - 8;
	}

	public int getViewSpaceHeight() {
		// return rlayAgendaView.getHeight();
		return 340;
	}

	public boolean startReminderService() {
		ComponentName cpn = startService(new Intent(TaskManager.this,
				AlarmService.class));
		return (cpn != null);
	}

	/*
	 * public void StopReminderService() { stopService(new Intent(TaskManager.this,
	 * AlarmService.class)); }
	 */

	public static boolean updateReminderService(Context context, Prefs prefs,
			String sKey) {
		Bundle args = new Bundle();
		args.putBoolean(sKey, true);
		// put additional prefs
		args.putBoolean("b24HourMode", prefs.b24HourMode);
		args.putInt("iFirstDayOfWeek", prefs.iFirstDayOfWeek);
		args.putInt("iSnoozeCount", prefs.iSnoozeCount);
		args.putInt("iSnoozeMinutesOverdue", prefs.iSnoozeMinutesOverdue);
		// update service
		Intent intent = new Intent(context, AlarmService.class);
		intent.putExtras(args);
		ComponentName cpn = context.startService(intent);
		return (cpn != null);
	}

	@Override
	protected void restoreStateFromFreeze() {
	}
}
